<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="96px">
      <el-form-item label="导入批次号" prop="batchNo">
        <el-input
          v-model="queryParams.batchNo"
          placeholder="请输入导入批次号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="督导任务时间" prop="taskStartTime">-->
<!--        <el-date-picker-->
<!--          v-model="daterangeDate"-->
<!--          style="width: 240px"-->
<!--          value-format="yyyy-MM-dd HH:mm:ss"-->
<!--          type="daterange"-->
<!--          range-separator="-"-->
<!--          start-placeholder="开始日期"-->
<!--          end-placeholder="结束日期"-->
<!--          :default-time="['00:00:00', '23:59:59']"-->
<!--        ></el-date-picker>-->
<!--      </el-form-item>-->
      <el-form-item label="督导社区" prop="community">
        <el-select v-model="queryParams.community" placeholder="请输入督导社区" clearable>
          <el-option
            v-for="dict in dict.type.erecord_community"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="项目名称" prop="itemName">
        <el-select v-model="queryParams.itemName" placeholder="请选择项目名称" clearable>
          <el-option
            v-for="dict in dict.type.erecord_item_name_list"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="督导人员" prop="superintendentUserName">
        <el-input
          v-model="queryParams.superintendentUserName"
          placeholder="请输入督导人员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="督导投放点" prop="deliveryName">
        <el-input
          v-model="queryParams.deliveryName"
          placeholder="请输入督导投放点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['standingbook:sortingImportDetail:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['standingbook:sortingImportDetail:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['standingbook:sortingImportDetail:remove']"
        >删除</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="warning"-->
<!--          plain-->
<!--          icon="el-icon-download"-->
<!--          size="mini"-->
<!--          @click="handleExport"-->
<!--          v-hasPermi="['standingbook:sortingImportDetail:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="sortingImportDetailList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column align="center" label="序号" width="55">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="导入批次号" align="center" prop="batchNo" width="180" />
      <el-table-column label="项目名称" align="center" prop="itemName" />
      <el-table-column label="日期" align="center" prop="date" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="督导社区" align="center" prop="community" />
<!--      <el-table-column label="督导任务时间（开始）" align="center" prop="taskStartTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.taskStartTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="督导任务时间（结束）" align="center" prop="taskEndTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.taskEndTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="督导收集点名称" align="center" prop="collectionName" width="120"/>
      <el-table-column label="督导投放点名称" align="center" prop="deliveryName" width="120"/>
      <el-table-column label="督导人员" align="center" prop="superintendentUserName" />
      <el-table-column label="督导人员手机号码" align="center" prop="superintendentUserPhone" width="140"/>
<!--      <el-table-column label="规定督导时间(开始)" align="center" prop="startTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="规定督导时间(结束)" align="center" prop="endTime" width="180">-->
<!--        <template slot-scope="scope">-->
<!--          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
      <el-table-column label="督导要求" align="center" prop="supervisionAsk" width="200"/>
      <el-table-column label="实际上岗时间" align="center" prop="actualStartTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualStartTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="实际签退时间" align="center" prop="actualEndTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.actualEndTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="督导时长" align="center" prop="actualDuration" />
<!--      <el-table-column label="本月累计督导时长" align="center" prop="thisMonthActualDuration" width="150"/>-->
      <el-table-column label="责任单位" align="center" prop="department" width="150"/>
      <el-table-column label="督导员管理人" align="center" prop="supervisorManagerUserName" width="130"/>
      <el-table-column label="督导员管理人手机号码" align="center" prop="supervisorManagerUserPhone" width="150"/>
      <el-table-column label="督导定位情况" align="center" prop="gpsStatus" width="140"/>
      <el-table-column label="考勤状态" align="center" prop="checkStatus" />
      <el-table-column label="岗前培训图片" align="center" prop="pic1" width="130" >
        <template slot-scope="scope">
          <image-preview :src="scope.row.pic1Url" :width="50" :height="50"/>
<!--          <image-preview :src="scope.row.pic2Url" :width="50" :height="50" style="margin-left:5px"/>-->
        </template>
      </el-table-column>
      <el-table-column label="现场督导图片" align="center" prop="pic3" width="130">
        <template slot-scope="scope">
          <image-preview :src="scope.row.pic3Url" :width="50" :height="50"/>
<!--          <image-preview :src="scope.row.pic4Url" :width="50" :height="50" style="margin-left:5px"/>-->
        </template>
      </el-table-column>
      <el-table-column label="厨余垃圾情况图片" align="center" prop="pic5" width="130" >
        <template slot-scope="scope">
          <image-preview :src="scope.row.pic5Url" :width="50" :height="50"/>
<!--          <image-preview :src="scope.row.pic6Url" :width="50" :height="50" style="margin-left:5px"/>-->
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理状态" align="center" prop="processStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_common_status" :value="scope.row.processStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="处理信息" align="center" prop="processMsg" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['standingbook:sortingImportDetail:edit']"-->
<!--          >修改</el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['standingbook:sortingImportDetail:remove']"-->
<!--          >删除</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改垃圾分类督导导入明细对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="导入批次号" prop="batchNo">
          <el-input v-model="form.batchNo" placeholder="请输入导入批次号" />
        </el-form-item>
        <el-form-item label="项目名称" prop="itemName">
          <el-input v-model="form.itemName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="日期" prop="date">
          <el-date-picker clearable
            v-model="form.date"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="督导社区" prop="community">
          <el-input v-model="form.community" placeholder="请输入督导社区" />
        </el-form-item>
        <el-form-item label="督导任务时间" prop="taskStartTime">
          <el-date-picker clearable
            v-model="form.taskStartTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择督导任务时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="督导任务时间" prop="taskEndTime">
          <el-date-picker clearable
            v-model="form.taskEndTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择督导任务时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="督导收集点名称" prop="collectionName">
          <el-input v-model="form.collectionName" placeholder="请输入督导收集点名称" />
        </el-form-item>
        <el-form-item label="督导投放点名称" prop="deliveryName">
          <el-input v-model="form.deliveryName" placeholder="请输入督导投放点名称" />
        </el-form-item>
        <el-form-item label="督导人员id" prop="superintendentUserId">
          <el-input v-model="form.superintendentUserId" placeholder="请输入督导人员id" />
        </el-form-item>
        <el-form-item label="督导人员" prop="superintendentUserName">
          <el-input v-model="form.superintendentUserName" placeholder="请输入督导人员" />
        </el-form-item>
        <el-form-item label="督导人员手机号码" prop="superintendentUserPhone">
          <el-input v-model="form.superintendentUserPhone" placeholder="请输入督导人员手机号码" />
        </el-form-item>
        <el-form-item label="规定督导时间(开始)" prop="startTime">
          <el-date-picker clearable
            v-model="form.startTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择规定督导时间(开始)">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="规定督导时间(结束)" prop="endTime">
          <el-date-picker clearable
            v-model="form.endTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择规定督导时间(结束)">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="督导要求" prop="supervisionAsk">
          <el-input v-model="form.supervisionAsk" placeholder="请输入督导要求" />
        </el-form-item>
        <el-form-item label="实际上岗时间" prop="actualStartTime">
          <el-date-picker clearable
            v-model="form.actualStartTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择实际上岗时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="实际签退时间" prop="actualEndTime">
          <el-date-picker clearable
            v-model="form.actualEndTime"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="请选择实际签退时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="督导时长" prop="actualDuration">
          <el-input v-model="form.actualDuration" placeholder="请输入督导时长" />
        </el-form-item>
        <el-form-item label="本月累计督导时长" prop="thisMonthActualDuration">
          <el-input v-model="form.thisMonthActualDuration" placeholder="请输入本月累计督导时长" />
        </el-form-item>
        <el-form-item label="责任单位" prop="department">
          <el-input v-model="form.department" placeholder="请输入责任单位" />
        </el-form-item>
        <el-form-item label="督导员管理人id" prop="supervisorManagerUserId">
          <el-input v-model="form.supervisorManagerUserId" placeholder="请输入督导员管理人id" />
        </el-form-item>
        <el-form-item label="督导员管理人" prop="supervisorManagerUserName">
          <el-input v-model="form.supervisorManagerUserName" placeholder="请输入督导员管理人" />
        </el-form-item>
        <el-form-item label="督导员手机号码" prop="supervisorManagerUserPhone">
          <el-input v-model="form.supervisorManagerUserPhone" placeholder="请输入督导员手机号码" />
        </el-form-item>
        <el-form-item label="岗前培训图片" prop="pic1">
          <el-input v-model="form.pic1" placeholder="请输入岗前培训图片" />
        </el-form-item>
        <el-form-item label="岗前培训图片2" prop="pic2">
          <el-input v-model="form.pic2" placeholder="请输入岗前培训图片2" />
        </el-form-item>
        <el-form-item label="现场督导图片" prop="pic3">
          <el-input v-model="form.pic3" placeholder="请输入现场督导图片" />
        </el-form-item>
        <el-form-item label="现场督导图片2" prop="pic4">
          <el-input v-model="form.pic4" placeholder="请输入现场督导图片2" />
        </el-form-item>
        <el-form-item label="厨余垃圾情况图片" prop="pic5">
          <el-input v-model="form.pic5" placeholder="请输入厨余垃圾情况图片" />
        </el-form-item>
        <el-form-item label="厨余垃圾情况图片2" prop="pic6">
          <el-input v-model="form.pic6" placeholder="请输入厨余垃圾情况图片2" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="处理信息" prop="processMsg">
          <el-input v-model="form.processMsg" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSortingImportDetail, getSortingImportDetail, delSortingImportDetail, addSortingImportDetail, updateSortingImportDetail } from "@/api/standingbook/sortingImportDetail";

export default {
  name: "SortingImportDetail",
  dicts: ['erecord_item_name_list','erecord_community','sys_common_status'],
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 垃圾分类督导导入明细表格数据
      sortingImportDetailList: [],
      // 弹出层标题
      title: "",
      // 是否新增
      isAdd : true,
      // 是否显示弹出层
      open: false,
      //督导任务时间
      daterangeDate: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        batchNo: undefined,
        itemName: undefined,
        date: undefined,
        community: undefined,
        taskStartTime: undefined,
        taskEndTime: undefined,
        collectionName: undefined,
        deliveryName: undefined,
        superintendentUserId: undefined,
        superintendentUserName: undefined,
        superintendentUserPhone: undefined,
        startTime: undefined,
        endTime: undefined,
        supervisionAsk: undefined,
        actualStartTime: undefined,
        actualEndTime: undefined,
        actualDuration: undefined,
        thisMonthActualDuration: undefined,
        department: undefined,
        supervisorManagerUserId: undefined,
        supervisorManagerUserName: undefined,
        supervisorManagerUserPhone: undefined,
        gpsStatus: undefined,
        checkStatus: undefined,
        pic1: undefined,
        pic2: undefined,
        pic3: undefined,
        pic4: undefined,
        pic5: undefined,
        pic6: undefined,
        processStatus: undefined,
        processMsg: undefined,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    const batchNo = this.$route.params && this.$route.params.batchNo;
    if (batchNo) {
      this.queryParams.batchNo = batchNo;
    }
    this.getList();
  },
  methods: {
    /** 查询垃圾分类督导导入明细列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeDate && '' != this.daterangeDate) {
        this.queryParams.params["taskStartTime"] = this.daterangeDate[0];
        this.queryParams.params["taskEndTime"] = this.daterangeDate[1];
      }
      listSortingImportDetail(this.queryParams).then(response => {
        this.sortingImportDetailList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        batchNo: undefined,
        itemName: undefined,
        date: undefined,
        community: undefined,
        taskStartTime: undefined,
        taskEndTime: undefined,
        collectionName: undefined,
        deliveryName: undefined,
        superintendentUserId: undefined,
        superintendentUserName: undefined,
        superintendentUserPhone: undefined,
        startTime: undefined,
        endTime: undefined,
        supervisionAsk: undefined,
        actualStartTime: undefined,
        actualEndTime: undefined,
        actualDuration: undefined,
        thisMonthActualDuration: undefined,
        department: undefined,
        supervisorManagerUserId: undefined,
        supervisorManagerUserName: undefined,
        supervisorManagerUserPhone: undefined,
        gpsStatus: undefined,
        checkStatus: undefined,
        pic1: undefined,
        pic2: undefined,
        pic3: undefined,
        pic4: undefined,
        pic5: undefined,
        pic6: undefined,
        remark: undefined,
        processStatus: undefined,
        processMsg: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        delFlag: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeDate = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.isAdd = true;
      this.title = "添加垃圾分类督导导入明细";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getSortingImportDetail(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.open = true;
        this.isAdd = false;
        this.title = "修改垃圾分类督导导入明细";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          if (this.isAdd == false) {
            updateSortingImportDetail(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          } else {
            addSortingImportDetail(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            }).finally(() => {
              this.buttonLoading = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除数据？').then(() => {
        this.loading = true;
        return delSortingImportDetail(ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('standingbook/sortingImportDetail/export', {
        ...this.queryParams
      }, `sortingImportDetail_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
